package com.atguigu.spark.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

import scala.collection.mutable

object Spark01 {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf().setMaster("local").setAppName("WordCount")
    conf .set("spark.testing.memory","2147480000")
    val sc: SparkContext = new SparkContext(conf)
    val list: RDD[String] = sc.textFile("spark-core/data/word.txt")
    val words: RDD[String] = list.flatMap(line => line.split(" "))
    val wordMap: RDD[(String, Int)] = words.map(word => (word, 1))
    wordMap.reduceByKey(_+_).collect().foreach(println)
    sc.stop()
  }
}